<?php
header("charset: utf-8");
?>
<html>
<head>
  <meta charset="utf-8">
  <style>
    img {
      max-width: 500px;
    }
  </style>
</head>
<body>
<pre>
<?php
$id = $_POST['id'];
if (true) {
  //var_dump($_FILES);
$pic1 = $_FILES['pic1'];
$res1 = exec("curl -T ${pic1['tmp_name']} -H 'Content-Type: image/png' http://oss.matrixsci.cn/ned/coupon/popup/${id}.png");
$pic2 = $_FILES['pic2'];
$res2 = exec("curl -T ${pic2['tmp_name']} -H 'Content-Type: image/png' http://oss.matrixsci.cn/ned/coupon/listitem/${id}.png");
$pic3 = $_FILES['pic3'];
$res3 = exec("curl -T ${pic3['tmp_name']} -H 'Content-Type: image/png' http://oss.matrixsci.cn/ned/coupon/detail/${id}.png");
}

$itemsWithCoupon = json_decode(file_get_contents('https://www.matrixsci.cn/baby/constant/get?key=items_with_coupon'), true)['message'];
//var_dump($itemsWithCoupon);
if (!$itemsWithCoupon) {
  $itemsWithCoupon = [];
} else {
  $itemsWithCoupon = explode(",", $itemsWithCoupon);
}
if (!in_array($id, $itemsWithCoupon)) {
  $itemsWithCoupon[] = $id;
  //var_dump($itemsWithCoupon);
  $value = implode(',', $itemsWithCoupon);
  $res4 = exec("curl -d 'key=items_with_coupon&value=${value}' http://www.matrixsci.cn/baby/constant/set");
  var_dump($res4);
} else {
  $res4msg = '数据已更新';
}
?>
</pre>

<?php if($res1 === ''): ?>
<p>页内图上传成功</p>
<img src="http://oss.matrixsci.cn/ned/coupon/popup/<?=$id?>.png">
<?php else: ?>
<p>页内图上传失败</p>
var_dump($res1);
<?php endif; ?>

<?php if($res2 === ''): ?>
<p>列表图上传成功</p>
<img src="http://oss.matrixsci.cn/ned/coupon/listitem/<?=$id?>.png">
<?php else: ?>
<p>列表图上传失败</p>
var_dump($res2);
<?php endif; ?>

<?php if($res3 === ''): ?>
<p>详情图上传成功</p>
<img src="http://oss.matrixsci.cn/ned/coupon/detail/<?=$id?>.png">
<?php else: ?>
<p>详情图上传失败</p>
var_dump($res3);
<?php endif; ?>

<?php if($res4 === ''): ?>
<p>数据更新成功</p>
<?php elseif($res4msg): ?>
<p><?=$res4msg?></p>
<?php else: ?>
<p>数据更新失败</p>
var_dump($res4);
<?php endif; ?>

<a href="coupon.html">返回</a>
</body>
</html>
